#include "pointstream.h"
#include <QDebug>

PointStream::PointStream(QObject *parent) : QObject(parent)
{
    pointList.reserve(MAX_BUFFER_SIZE);
}
QList<QPointF> PointStream::getRecentPoints(int numPoints)
{
    QList<QPointF> temp;

    int begin = pointList.count() - numPoints;
    if(begin < 0) {
        begin = 0;
    }

    for(int i=begin; i<pointList.count(); i++) {
        temp << pointList[i];
    }

    return temp;
}
int PointStream::getSamplesPerSeconds() const
{
    return samplesPerSeconds;
}

void PointStream::setSamplesPerSeconds(int value)
{
    samplesPerSeconds = value;
}
void PointStream::appendPoints(const QPointF &newPoint)
{
    if(pointList.size() + 1 > MAX_BUFFER_SIZE) {
        discardPoints((pointList.size() + 1)-MAX_BUFFER_SIZE);
    }

    pointList.append(newPoint);
}

void PointStream::discardPoints(int numPoints) {
    for(int i=0; i<numPoints; i++) {
        //Recomendação do Qt para QList<T>.takeFirst()
        //Verification recommended in Qt docummentation
        if(!pointList.isEmpty()) {
            pointList.removeFirst();
        }
        else {
            return;
        }
    }
}

